package com.hugesoft.commonlogic.dao;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;

import com.hugesoft.logic.module.BusDao;
import com.hugesoft.logic.module.DaoMaster;
import com.hugesoft.logic.module.DaoMaster.DevOpenHelper;
import com.hugesoft.logic.module.DaoSession;
import com.hugesoft.logic.module.DriverLicenceDao;
import com.hugesoft.logic.module.PoliceDao;
import com.hugesoft.logic.module.TrafficDao;

public class DbManager
{
	//账户数据库名
	public static final String USER_DATABASE = "jxgs.db";
	protected static DbManager gDbManager = null;
	
	protected SQLiteDatabase mDb = null;
	protected DaoMaster mDaoMaster = null;
	protected DaoSession mDaoSession = null;
	
	protected static String mCurrentDBName = USER_DATABASE;
	
//	public static void initDbManager(Context context)
//	{
//		gDbManager = new DbManager(context, DB_NAME);
//	}
	
	public static DbManager getDbManager()
	{
		return DaoManager.shareManager().getDbManager(mCurrentDBName);
	}
	
	protected DbManager(Context context, String db)
	{
		DevOpenHelper helper = new DevOpenHelper(context, db, null);
		mDb = helper.getWritableDatabase();
		
		if (mDb == null) return;
		
		mDaoMaster = new DaoMaster(mDb);
		mDaoSession = mDaoMaster.newSession();
	}
	
//	public static void setCurrentAccount(Long accountId)
//	{
//		String accountString = String.valueOf(accountId);
//		mCurrentDBName = String.format(USER_DATABASE, accountString);
//		
//	}

	public DaoMaster getmDaoMaster()
	{
		return mDaoMaster;
	}

	public DaoSession getmDaoSession()
	{
		return mDaoSession;
	}
	
	public static PoliceDao getPoliceDao()
	{
		return getDbManager().getmDaoSession().getPoliceDao();
	}
	
	public static BusDao getBusDao()
	{
		return getDbManager().getmDaoSession().getBusDao();
	}
	
	public static TrafficDao getTrafficDao()
	{
		return getDbManager().getmDaoSession().getTrafficDao();
	}
	
	public static DriverLicenceDao getDriverlicenceDao()
	{
		return getDbManager().getmDaoSession().getDriverLicenceDao();
	}
}
